﻿
Partial Class WebForm_AssetMaintain_Component_AssetReply
    Inherits BaseUserControl
    Public Sub Show()
        mpSearch.Show()
    End Sub
    Public Sub IniData(ByVal assetdef_id As String, ByVal asset_serialNo As String, ByVal Kind As String, ByVal dbName As String, ByVal UID As String)
        ViewState("assetdef_id") = assetdef_id

        ViewState("asset_serialNo") = asset_serialNo
        hiDBName.Value = dbName
        ViewState("UID") = UID
        '//2011/12/18日 目前發現每位同仁都可以幫別人回報
        Dim gDao As OAMS.DAO.GroupDAO = New OAMS.DAO.GroupDAO(dbName)

        If gDao.GroupMemberIsExist("Admin", ActualUID) Then
            txtasset_owner.ReadOnly = False
        Else
            txtasset_owner.ReadOnly = True
        End If
        '====================================================
        ddlassetdef_id.DataBind()
        ddlassetdef_id.SelectedValue = assetdef_id
        ddlKind.SelectedValue = Kind
        txtasset_owner.Text = UID
        txtasset_serialNo.Text = asset_serialNo
    End Sub

    
    

    Protected Sub chkReply_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim asset_serialNo As String = CType(sender, CheckBox).ToolTip

        For Each gr As GridViewRow In gvMain.Rows
            If HttpUtility.HtmlDecode(gr.Cells(2).Text).Trim = asset_serialNo.Trim Then
               


            End If
        Next

        mpSearch.Show()
        objSetFocus(sender)
    End Sub

    Protected Sub chkCancel_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim asset_serialNo As String = CType(sender, CheckBox).ToolTip

        For Each gr As GridViewRow In gvMain.Rows
            If HttpUtility.HtmlDecode(gr.Cells(2).Text).Trim = asset_serialNo.Trim Then
                If ddlKind.SelectedValue = "1" Then
                    gr.FindControl("chkReply").Visible = True
                    gr.FindControl("chkCancel").Visible = False
                Else
                    gr.FindControl("chkReply").Visible = False
                    gr.FindControl("chkCancel").Visible = True

                End If

                If CType(sender, CheckBox).Checked Then
                    gr.FindControl("ddlReason").Visible = True
                    gr.FindControl("lblReason").Visible = True
                    Exit For
                Else

                    gr.FindControl("ddlReason").Visible = False
                    gr.FindControl("lblReason").Visible = False
                    Exit For
                End If


            End If
        Next
        mpSearch.Show()
        objSetFocus(sender)
    End Sub

    Protected Sub ddlReason_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim asset_serialNo As String = CType(sender, DropDownList).ToolTip

        For Each gr As GridViewRow In gvMain.Rows
            If HttpUtility.HtmlDecode(gr.Cells(2).Text).Trim = asset_serialNo.Trim Then
                If CType(gr.FindControl("ddlReason"), DropDownList).SelectedValue = "2" Then
                    gr.FindControl("lblMemo").Visible = True
                    gr.FindControl("txtMemo").Visible = True
                    Exit For

                Else
                    gr.FindControl("lblMemo").Visible = False
                    gr.FindControl("txtMemo").Visible = False
                    Exit For
                End If


            End If
        Next

        mpSearch.Show()
        objSetFocus(sender)
    End Sub

   
    Protected Sub gvMain_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvMain.SelectedIndexChanged
        mpSearch.Show()
    End Sub

   

    Protected Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
        ''將把V的資料回報/取消回報
        Dim aBBl As AssetManage.BBL.AssetBBL = New AssetManage.BBL.AssetBBL()
        For Each gr As GridViewRow In gvMain.Rows
            If ddlKind.SelectedValue = "1" Then ''回報
                If CType(gr.FindControl("chkReply"), CheckBox).Checked Then
                    aBBl.UpdateReply(gr.Cells(2).Text, ActualUID, "", "", "3", hiDBName.Value)
                End If
            Else
                If CType(gr.FindControl("chkCancel"), CheckBox).Checked Then
                    aBBl.UpdateReply(gr.Cells(2).Text, ActualUID, CType(gr.FindControl("ddlReason"), DropDownList).SelectedValue, CType(gr.FindControl("txtMemo"), TextBox).Text, "5", hiDBName.Value)
                End If

            End If

        Next


        '資料要重新查詢才可以
        gvMain.DataBind()
        mpSearch.Show()
        ShowMessageForAjax(btnCancel, GetLocalResourceObject("Finish"))
    End Sub

    Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnQuery.Click
        gvMain.DataBind()
        mpSearch.Show()
    End Sub

 
    Protected Sub gvMain_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvMain.RowCreated
        If e.Row.RowType = DataControlRowType.DataRow Then
            If ddlKind.SelectedValue = "1" Then
                e.Row.FindControl("chkReply").Visible = True
                e.Row.FindControl("chkCancel").Visible = False
            Else
                e.Row.FindControl("chkReply").Visible = False
                e.Row.FindControl("chkCancel").Visible = True

            End If
        End If

        If e.Row.RowType = DataControlRowType.Header Then
            If ddlKind.SelectedValue = "1" Then
                e.Row.FindControl("chkReplyHead").Visible = True
                e.Row.FindControl("chkCancelHead").Visible = False
            Else
                e.Row.FindControl("chkReplyHead").Visible = False
                e.Row.FindControl("chkCancelHead").Visible = True

            End If
        End If

    End Sub

    Protected Sub chkCancelHead_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim chk As Boolean = CType(sender, CheckBox).Checked

        For Each gr As GridViewRow In gvMain.Rows
            CType(gr.FindControl("chkCancel"), CheckBox).Checked = chk

        Next

        mpSearch.Show()
    End Sub

    Protected Sub ddlKind_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlKind.SelectedIndexChanged
        gvMain.DataBind()
        mpSearch.Show()
    End Sub

    Protected Sub chkReplyHead_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim chk As Boolean = CType(sender, CheckBox).Checked

        For Each gr As GridViewRow In gvMain.Rows
            CType(gr.FindControl("chkReply"), CheckBox).Checked = chk

        Next

        mpSearch.Show()
    End Sub

    Protected Sub gvMain_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvMain.PageIndexChanged
        mpSearch.Show()
    End Sub
End Class
